multiselection: Make constructor transfer full
authorMatthias Clasen <mclasen@redhat.com>
Sun, 26 Jul 2020 21:25:06 +0000 (17:25 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 26 Jul 2020 22:04:40 +0000 (18:04 -0400)
This is for consistency with other wrapping list constructors.
We want them all to be transfer full, allow-none.

Also make the constructor return GtkMultiSelection *.

Update all callers.

demos/gtk-demo/listview_colors.c
gtk/gtkmultiselection.c
gtk/gtkmultiselection.h
testsuite/gtk/multiselection.c

index 94210bf9ceaa6aa0f549135948cb196460275ab2..a1533b84322fb48d482adc76463c86efd8efd8a4 100644 (file)
@@ -884,7 +884,7 @@ do_listview_colors (GtkWidget *do_widget)
 
       sort_model = gtk_sort_list_model_new (gtk_color_list_new (0), NULL);
       gtk_sort_list_model_set_incremental (sort_model, TRUE);
-      selection = GTK_MULTI_SELECTION (gtk_multi_selection_new (G_LIST_MODEL (sort_model)));
+      selection = gtk_multi_selection_new (G_LIST_MODEL (sort_model));
 
       window = gtk_window_new ();
       gtk_window_set_title (GTK_WINDOW (window), "Colors");
index 6c754f77a8b1822e4a03bf1968084d126b5eea5e..c6e3474cb9bfc35e041824ce6fc5569fc88d70f4 100644 (file)
@@ -370,20 +370,27 @@ gtk_multi_selection_init (GtkMultiSelection *self)
 
 /**
  * gtk_multi_selection_new:
- * @model: (transfer none): the #GListModel to manage
+ * @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL
  *
  * Creates a new selection to handle @model.
  *
- * Returns: (transfer full) (type GtkMultiSelection): a new #GtkMultiSelection
+ * Returns: (transfer full): a new #GtkMultiSelection
  **/
-GListModel *
+GtkMultiSelection *
 gtk_multi_selection_new (GListModel *model)
 {
+  GtkMultiSelection *self;
+
   g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
 
-  return g_object_new (GTK_TYPE_MULTI_SELECTION,
+  self = g_object_new (GTK_TYPE_MULTI_SELECTION,
                        "model", model,
                        NULL);
+
+  /* consume the reference */
+  g_clear_object (&model);
+
+  return self;
 }
 
 /**
index 69c8a6902809a4699ca5c29a8df0a0f55d98913b..b8e0300ed19fb6c109801ec3ec7ca7bf3e991939 100644 (file)
@@ -31,13 +31,13 @@ GDK_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (GtkMultiSelection, gtk_multi_selection, GTK, MULTI_SELECTION, GObject)
 
 GDK_AVAILABLE_IN_ALL
-GListModel *    gtk_multi_selection_new                (GListModel           *model);
+GtkMultiSelection * gtk_multi_selection_new                (GListModel           *model);
 
 GDK_AVAILABLE_IN_ALL
-GListModel *    gtk_multi_selection_get_model          (GtkMultiSelection    *self);
+GListModel *        gtk_multi_selection_get_model          (GtkMultiSelection    *self);
 GDK_AVAILABLE_IN_ALL
-void            gtk_multi_selection_set_model          (GtkMultiSelection    *self,
-                                                        GListModel           *model);
+void                gtk_multi_selection_set_model          (GtkMultiSelection    *self,
+                                                            GListModel           *model);
 
 G_END_DECLS
 
index 3e3fa39c77dad1f4cfe4cb0cdc6b2b782425ee9a..2c23168d07ebf67be39f0e8a55a42c5a585ec1a8 100644 (file)
@@ -253,7 +253,7 @@ new_model (GListStore *store)
   GtkSelectionModel *result;
   GString *changes;
 
-  result = GTK_SELECTION_MODEL (gtk_multi_selection_new (G_LIST_MODEL (store)));
+  result = GTK_SELECTION_MODEL (gtk_multi_selection_new (g_object_ref (G_LIST_MODEL (store))));
 
   changes = g_string_new ("");
   g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);